package com.kevin.designpattern.chain_responsibility;

public abstract class Handler {

    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    // 盖领导处理请求的天数区间
    private int numStart;
    private int numEnd;

    //声明后继者
    private Handler nextHandler;


    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 各级领导处理请假条的方法
    protected abstract void handlerLeave(LeaveRequest leaveRequest);

    //提交请假条
    public final void submit(LeaveRequest leaveRequest) {
        // 该领导直接进行审批
        this.handlerLeave(leaveRequest);
        if (this.nextHandler != null && leaveRequest.getNum() > this.numEnd) {
            // 超出审批天数区间，提交给上级领导进行审批
            this.nextHandler.submit(leaveRequest);
        } else {
            // 没有的话直接审批完成后，流程宣布结束
            System.out.println("请假流程结束！");
        }
    }
}
